package domain;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

import util.DateUtil;

@Entity
public class Mission implements Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	@Id @GeneratedValue
	private long id;
	private Timestamp startTime;
	private Timestamp endTime;
	private Timestamp completeTime;
	
	@Enumerated(EnumType.STRING)
	private DeliveryType devType;
	
	@Enumerated(EnumType.STRING)
	private MissionStatus status;
	
	@ManyToOne(fetch=FetchType.EAGER)
	private POS fromPOS;
	
	@ManyToOne(fetch=FetchType.EAGER)
	private POS toPOS;
	
	private int priority;
	private int weight;
	
	@OneToMany(fetch=FetchType.EAGER)
	private List<Envelope> envelopes = new ArrayList<Envelope>();
	
	// Getter and Setter
	public int getWeight() {
		return weight;
	}
	public void setWeight(int weight) {
		this.weight = weight;
	}
	public MissionStatus getStatus() {
		return status;
	}
	public void setStatus(MissionStatus status) {
		this.status = status;
	}
	public long getId() {
		return id;
	}
	public void setId(long id) {
		this.id = id;
	}
	public DeliveryType getDevType() {
		return devType;
	}
	public void setDevType(DeliveryType devType) {
		this.devType = devType;
	}
	public POS getFromPOS() {
		return fromPOS;
	}
	public void setFromPOS(POS fromPOS) {
		this.fromPOS = fromPOS;
	}
	public POS getToPOS() {
		return toPOS;
	}
	public void setToPOS(POS toPOS) {
		this.toPOS = toPOS;
	}
	public int getPriority() {
		return priority;
	}
	public void setPriority(int priority) {
		this.priority = priority;
	}
	public List<Envelope> getEnvelopes() {
		return envelopes;
	}
	public void addEnvelopes(Envelope envelope) {
		this.envelopes.add(envelope);
	}
	public Timestamp getStartTime() {
		return startTime;
	}
	public void setStartTime(Timestamp startTime) {
		this.startTime = startTime;
	}
	public Timestamp getEndTime() {
		return endTime;
	}
	public void setEndTime(Timestamp endTime) {
		this.endTime = endTime;
	}
	public Timestamp getCompleteTime() {
		return completeTime;
	}
	public void setCompleteTime(Timestamp completeTime) {
		this.completeTime = completeTime;
	}
	
	
	//Domain Logic
	public void updateCompelteStatus(){
		this.status = MissionStatus.complete;
		this.completeTime = DateUtil.getCurrentTimestamp();
	}
}
